<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="archsw0904.controller.registration.*"%>
<%@ page import="java.net.URLEncoder"%>
<%
	request.setCharacterEncoding(application
			.getInitParameter("PARAMETER_ENCODING"));
	String errorMessage = null;

	if (request.getMethod().compareToIgnoreCase("post") == 0) {
		String name = request.getParameter("name");
		String surname = request.getParameter("surname");
		String email = request.getParameter("email");
		String password = request.getParameter("password");
		String city = request.getParameter("city");
		String address = request.getParameter("address");
		String cap = request.getParameter("cap");
		String state = request.getParameter("state");
		String telephone = request.getParameter("telephone");
		RegistrationBeanServiceLocator regServiceLocation = new RegistrationBeanServiceLocator();
		regServiceLocation.setRegistrationBeanPortEndpointAddress( application
				.getInitParameter("REGISTRATION_WEB_SERVICE_URI") );
		RegistrationBean rb = regServiceLocation
				.getRegistrationBeanPort();
		try {
			rb.createProfile(password, name, surname, email, address,
					cap, city, telephone, state);
			String redicect = "/BookShopWeb/page/login.jsp?refererOverride="
					+ URLEncoder
							.encode("/BookShopWeb/page/clientInfo.jsp")
					+ "&username="
					+ URLEncoder.encode(email)
					+ "&password="
					+ URLEncoder.encode(password)
					+ "&action=login";
			response.sendRedirect(redicect);
		} catch (NullMandatoryFieldException e) {
			errorMessage = e.getField();
		}

	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<jsp:include page="/partial/process_cache.jsp" />
<jsp:useBean id="usercache" scope="session"
	class="session.cache.UserCache" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration @ <%=usercache.getHostingNode()%></title>
</head>
<body>
<jsp:include page="/partial/head_menu.jsp" />

<form action="/BookShopWeb/page/registration.jsp" method="post">
<table>
	<tr>
		<td><b>Name*</b></td>
		<td><input type="text" name="name" size="12" /></td>
	</tr>

	<tr>
		<td><b>Surname*</b></td>
		<td><input type="text" name="surname" size="12" /></td>
	</tr>
	<tr>
		<td><b>Email(future username)*</b></td>
		<td><input type="text" name="email" size="12" /></td>
	</tr>

	<tr>
		<td><b>Password*</b></td>
		<td><input type="password" name="password" size="12" /></td>
	</tr>

	<tr>
		<td><b>City</b></td>
		<td><input type="text" name="city" size="12" /></td>
	</tr>

	<tr>
		<td><b>Address</b></td>
		<td><input type="text" name="address" size="12" /></td>
	</tr>

	<tr>
		<td><b>CAP</b></td>
		<td><input type="text" name="cap" size="12" /></td>
	</tr>

	<tr>
		<td><b>State</b></td>
		<td><input type="text" name="state" size="12" /></td>
	</tr>

	<tr>
		<td><b>Telephone</b></td>
		<td><input type="text" name="telephone" size="12" /></td>
	</tr>
	<tr>
		<td colspan="2"><input type="submit" value="Register" /></td>
	</tr>
</table>
</form>
<%
	if (errorMessage != null) {
		out.println("<p><font color=\"red\"><b>Error: " + errorMessage
				+ "</b></font></p>");
	}
%>
</body>
</html>